package com.hy.lightning.boot.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hy.lightning.boot.web.servlet.bean.DefaultHttpServletRequest;
import com.hy.lightning.boot.web.servlet.bean.DefaultHttpServletResponse;

public class BaseFilter implements Filter {

	private FilterHandler filterHandler = new DefaultFilterHandler();
	
	public BaseFilter(FilterHandler filterHandler) {
		this.filterHandler = filterHandler;
	}
	
	public BaseFilter() {}
	
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		DefaultHttpServletRequest defaultServletRequest = new DefaultHttpServletRequest((HttpServletRequest) request);
		DefaultHttpServletResponse defaultServletResponse = new DefaultHttpServletResponse((HttpServletResponse) response);
		boolean b = filterHandler.filter(defaultServletRequest, defaultServletResponse);
		if(b)chain.doFilter(defaultServletRequest, defaultServletResponse);
		System.out.println("------------responseHandler-------------");
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		
	}

	@Override
	public void destroy() {
		
	}

}
